
local CreateMaterial, render, GetRenderTarget, ScrW, ScrH = CreateMaterial, render, GetRenderTarget, ScrW, ScrH
local MsgN = MsgN

module "framebuffer"

local MaterialComposite = CreateMaterial( "FrameBuffer", "UnlitGeneric", {
    ["$basetexture"] = "_rt_FullFrameFB",
    ["$ignorez"] = "1",
    ["$vertexcolor"] = "1",
    ["$vertexalpha"] = "1",
    ["$nolod"] = "1",
} )

local Framebuffer = render.GetMorphTex0()
local olRenderTarget = nil
local olScrW, olScrH
local isRendering = false

function Start()
	olScrW, olScrH = ScrW(), ScrH()
	olRenderTarget = render.GetRenderTarget()
	render.SetRenderTarget( Framebuffer )
	render.Clear( 0,0,0,0 )
	render.SetViewPort(0,0,512*2,512*2)
	isRendering = true
	render.SetBlend( 1 )
end

function End()
	render.SetBlend( 1 )
	render.SetRenderTarget( olRenderTarget )
	MaterialComposite:SetMaterialTexture( "$basetexture", Framebuffer )
	isRendering = false
	render.SetViewPort(0,0,olScrW, olScrH)
end

function IsRendering()
	return isRendering
end

function Get()
	return MaterialComposite
end